package com.chaoyi.service.Impl;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.Part;

import org.springframework.stereotype.Service;

import com.chaoyi.config.WSUploadConfig;
import com.chaoyi.dao.mysql.HomeMapper;
import com.chaoyi.model.Home;
import com.chaoyi.service.HomeService;
import com.chaoyi.util.UUIDUtil;
import com.chaoyi.util.oss.ApkOSSConfigure;
import com.chaoyi.util.oss.ApkOSSManageUtil;
import com.chaoyi.util.qiniu.UploadFileQiNiu;

@Service
public class HomeServiceImpl implements HomeService{
	@Resource
	HomeMapper homeMapper;
	@Override
	public List<Home> findList(String offset, String limit,String type) {
		return homeMapper.findList(offset,limit,type);
	}
	@Override
	public int saveHome(Home home) {
		return homeMapper.saveHome(home);
	}
	
	@Override
	public String uploadClassifyImg2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
//		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.privatePlayAvatarImgPath,
//				fileName);
		return UploadFileQiNiu.uploadFile(uploadFile, WSUploadConfig.privatePlayAvatarImgPath, fileName);
	}

	@Override
	public String uploadClassifyVideo2WSCDN(Part uploadFile) throws IOException, Exception {
		String exten = uploadFile.getSubmittedFileName().substring(uploadFile.getSubmittedFileName().lastIndexOf("."));
		String fileName = UUIDUtil.getUUID() + exten;
		return ApkOSSManageUtil.uploadFile(new ApkOSSConfigure(), uploadFile, WSUploadConfig.privatePlayAudioPath,
				fileName);
	}
	@Override
	public Home findHomeOne(int id) {
		return homeMapper.findHomeOne(id);
	}
	@Override
	public int alertHomeSave(Home home) {
		return homeMapper.alertHomeSave(home);
	}
	@Override
	public int deleteHome(int id) {
		return homeMapper.deleteHome(id);
	}
	@Override
	public int findCount(String type) {
		return homeMapper.findCount(type);
	}

}
